home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / quintus / quintus0.lha / work / clausify_18.7 < prev    next >
Text File  |  1992-04-03  |  1KB  |  52 lines

  1. %%% CLAUSIFY
  2. %%% version 18.7
  3. %%%
  4. %%% sprfn_to_clause:
  5. %%% Transform a clause form in implication form to a general form.
  6. %%%    Sprfn is a special case of implication form.
  7. %%%    head and body are separated by :- or equivalent operators.
  8. %%% replace_to_clause:
  9. %%% Transform a replace rule to a general clause, plus flags.
  10. %%%
  11.  
  12. %%% Declare the precedence of operators.
  13.      :- op( 1200, xfx, [ : ]).
  14.      :- op( 1200, xfx, [ :-- ]).
  15.      :- op( 1200, xfx, [ :-. ]).
  16.  
  17. %%% Transform one clause each time.
  18. %%% Head and body are separated by :-.
  19.      sprfn_to_clause((X :- Y),C) :-
  20.     make_and_list(Y, L1),
  21.     make_or_list(X, L2),
  22.     append(L2,L1,C), !.
  23. %%% Head and body are separated by :--.
  24.      sprfn_to_clause((X :-- Y),C) :-
  25.     make_and_list(Y, L1),
  26.     make_or_list(X, L2),
  27.     append(L2,L1,C), !.
  28. %%% Head and body are separated by :-..
  29.      sprfn_to_clause((X :-. Y),C) :-
  30.     make_and_list(Y, L1),
  31.     make_or_list(X, L2),
  32.     append(L2,L1,C), !.
  33. %%% positive clause.
  34.      sprfn_to_clause(X,C) :-
  35.     make_or_list(X, C).
  36.  
  37. %%% Transform the body into a list.
  38.      make_and_list((X,Y),Z) :-
  39.     make_and_list(X,Z1),
  40.     make_and_list(Y,Z2),
  41.     append(Z1,Z2,Z), !.
  42.      make_and_list(true,[]) :- !.
  43.      make_and_list(X,[Y]) :- negate(X,Y).
  44.  
  45. %%% Transform the head into a list.
  46.      make_or_list((X,Y),Z) :-
  47.     make_or_list(X,Z1),
  48.     make_or_list(Y,Z2),
  49.     append(Z1,Z2,Z), !.
  50.      make_or_list(false,[]) :- !.
  51.      make_or_list(X,[X]).
  52.